<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/view/system/common/head.jsp"%>

<body>
	<table style="width: 100%; height: 100%">
		<tr>
			<td style="width: 50%; vertical-align: top;">
				<form id="form1" name="form1" method="post" >
					<div id="p" class="easyui-panel" collapsible="true" style="padding:10px;">
						名称: <input type="text" id="qpName" name="qpName"
							 
							class="easyui-validatebox myInput" /> 类型:
						
						<select id="qpType" name="qpType"  class="easyui-combobox" style="width:100px;" >
						   <option value=""></option>
						   <c:forEach items="${parameterTypeList}" var="parameterTypeItem" >
						     <option value="${parameterTypeItem.value }">${parameterTypeItem.name }</option>
						  </c:forEach>
						 </select>
						 
						<a  class="easyui-linkbutton myLink" iconCls="icon-ok" style="margin-left:20px;"
					    onclick="queryDataGrid()">查询 </a>
					    
					    <a  class="easyui-linkbutton myLink" iconCls="icon-undo" style="margin-left:10px;"
					    onclick="restDataGrid()">重置 </a>
					</div>
					<table id="parameterDataGrid"></table>
				</form>
			</td>
			<td style="width: 50%; vertical-align: top;"><iframe
					id="parameterOperatorFrame"
					style="width: 100%; height: 100%; border:0px;" scrolling="yes"> </iframe></td>
		</tr>
	</table>
</body>
<script type="text/javascript">
$(document).ready(function() {
	setDataGridList();
});
//查询客户
function queryDataGrid() {
	var valid = $('#form1').form('validate');
	if (valid) {
		var param = $('#form1').serializeJson(true);
		 $('#parameterDataGrid').datagrid('load', param);
		
	}
}

var parameterTypeListJSON = eval('(${parameterTypeListJSON})');
//查询列表初始化
function setDataGridList() {
$('#parameterDataGrid').datagrid( {
		url : 'parameter/getParameterList.action',
		title : "参数列表",
		fitColumns:true,nowrap:false,rownumbers:true,showFooter:false,pagination:true,striped:true,singleSelect:false,
		idField : 'id',
		frozenColumns : [ [ {
			field : 'ck',
			checkbox : true
		} ] ],
		tools: [{iconCls: 'icon-reload',handler: function(){$('#parameterDataGrid').datagrid('reload');}}],
		toolbar : [ 
			{id:'btnadd',text:'增加',iconCls:'icon-add',handler:function(rowData){showAddParameter(rowData);}}
			,'-',{id:'btnremove',text:'删除',iconCls:'icon-remove',handler:function(){removeBatch();}}
			,'-',{id:'btnrefresh',text:'刷新',iconCls:'icon-reload',handler:function(){$('#parameterDataGrid').datagrid('reload');}}
		],
		columns:[[{field:'id',hidden:true,sortable:true}
			,{field:'code',title:"编码",width:20,sortable:true}
			,{field:'name',title:"名称",width:20,sortable:true}
			,{field:'value',title:"值",width:10,sortable:true}
			,{field:'type',title:"类型",width:20,sortable:true,
				formatter:function(val){
					if(val == '1'){
						return "单参数";
					}else{
						return "多参数";
					}
				}}
			
		]],
		onRowContextMenu : function(e, rowIndex, rowData) {
			e.preventDefault();
			$('#parameterDataGrid').datagrid('unselectAll');
			$('#parameterDataGrid').datagrid('selectRow', rowIndex);
			createColumnMenu(rowData);
			$('#tmenu').menu('show', {
				left : e.pageX,
				top : e.pageY
			});
		}
		,onDblClickRow: function (rowIndex, rowData) {
			if(rowData.type==2){
				$('#parameterDataGrid').datagrid('unselectAll');
				$('#parameterDataGrid').datagrid('selectRow', rowIndex);
				showParameterDetail(rowData);
			}
		}  
	});
}

var tmenu;
function createColumnMenu(rowData) {
	if (tmenu != null) {
		$("#tmenu").remove();
	}
	var menuStr = '<div id="tmenu" style="width:135px;">';
	menuStr += '<div data-options="iconCls:\'icon-edit\'" id ="update">修改</div>';
	menuStr += '<div data-options="iconCls:\'icon-remove\'" id ="remove">删除</div>';
	menuStr += '</div>';

	tmenu = $(menuStr).appendTo('body');
	//}
	tmenu.menu( {
		onClick : function(item) {
			 if (item.id == 'remove') {
			$.messager.confirm("提示", "确定要删除参数吗?", function(r) {
				if (r) {
					delParameter(rowData.id);
				}
			});
		} else if (item.id == 'update') {
			showParameterUpdate(rowData);
		}  
	}
})	;
}

//添加参数
function showAddParameter(rowData){
	document.getElementById("parameterOperatorFrame").src = "view/goParameterAdd.action";
}

//更新参数
function showParameterUpdate(rowData){
	document.getElementById("parameterOperatorFrame").src = "view/goParameterUpdate.action?parameterId="+rowData.id;
}


function showParameterDetail(rowData){
	document.getElementById("parameterOperatorFrame").src = "view/goParameterDetail.action?parameterId="+rowData.id;
}
function goParameterDetail(rowData){
	addTab('参数详情', 'view/goParameterDetail.action?parameterId='+rowData.id, '#tt', "parent.parent");
}

function doParameterAdd(){
	$.messager.alert('<s:text name="mes.message"/>', "已经打开新窗口添加角色，完成后点击确定刷新角色列表", 'info',function(){$('#parameterDataGrid').datagrid('reload');});
	addTab('参数添加', 'view/goParameterAdd.action', '#tt', "parent");
}



//批量删除
function removeBatch() {
	var rows = $('#parameterDataGrid').datagrid('getSelections');
	if (rows.length == 0) {
		$.messager.alert('确认信息', "请选择待操作的记录", 'info');
	} else {
		$.messager.confirm('<s:text name="mes.message"/>', "确定要删除选择的参数吗", function(r) {
			if (r) {
				var ids = getSelectedIds(rows);
				delParameter(ids);
			}
		});
	}
}

function getSelectedIds(rows) {
	var ids = [];
	for ( var i = 0; i < rows.length; i++) {
		ids.push(rows[i].id);
	}
	return ids.join(',');
}

function delParameter(ids){
	$.axs("parameter/doParameterRemove.action", {'parameterIds':ids}, 
            function(data){
		if(data.status == 1){
			$.messager.alert("提示信息",data.msg, 'info', function() {
				$('#parameterDataGrid').datagrid('load', getJSONParam());
				$('#parameterDataGrid').datagrid('getSelections').length=0;  //重设选中行
			//	clearIframe();
			});
		}else{
			$.messager.alert("提示信息", data.msg, 'error');
		}
	});	
}

function clearIframe(){
    var el =  document.getElementById('parameterOperatorFrame');
    var iframe = el.contentWindow;
    if(el){
        el.src = 'about:blank';
        try{
            iframe.document.write('');
            iframe.document.clear();
        }catch(e){};
        document.body.removeChild(el);
    }
}

function restDataGrid(){
	$('#form1').form("reset");
	queryDataGrid();
}


</script>
</html>